<template>
  <div
    :class="bgStyle===0 ? '' : 'pinkOn'"
    :style="{
      background: bgColor,
      marginTop: mTop + 'px',
      padding: '10px ' + prConfig + 'px'
    }" 
  >
    <div class="card_content">
      <h2
        class="m0"
        :style="[
          { textAlign: txtPosition },
          { fontWeight: txtStyle == 'bold' ? txtStyle : '' },
          { fontSize: fontSize + 'px' },
          { color: themeColor }
        ]"
      >
        {{ titleTxt }}：
      </h2>
      <p
        class="mt10"
        :style="[
          { fontSize: tipSize + 'px' },
          { color: txtColor }
        ]"
      >
        {{ tipTxt ? tipTxt : "专注MarTech应用开发" }}
      </p>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "home_card",
  cname: "个人介绍",
  icon: "iconbanquan",
  configName: "c_home_card",
  type: 3, // 0 基础组件 1 营销组件 2工具组件
  defaultName: "cardSign", // 外面匹配名称
  props: {
    index: {
      type: null
    },
    num: {
      type: null
    }
  },
  computed: {
    ...mapState("mobildConfig", ["defaultArray"])
  },
  watch: {
    pageData: {
      handler(nVal, oVal) {
        this.setConfig(nVal);
      },
      deep: true
    },
    num: {
      handler(nVal, oVal) {
        let data = this.$store.state.mobildConfig.defaultArray[nVal];
        this.setConfig(data);
      },
      deep: true
    },
    defaultArray: {
      handler(nVal, oVal) {
        let data = this.$store.state.mobildConfig.defaultArray[this.num];
        this.setConfig(data);
        console.log(data);
      },
      deep: true
    }
  },
  data() {
    return {
      // 默认初始化数据禁止修改
      defaultConfig: {
        name: "cardSign",
        timestamp: this.num,
        setUp: {
          tabVal: "0"
        },
        titleConfig: {
          title: "标题",
          value: "个人介绍",
          place: "请输入标题",
          max: 10
        },
        tipTxt: {
          title: "简介",
          value: "专注MarTech应用开发",
          place: "请输入简介",
          max: 300,
          type: "form"
        },
        bgStyle: {
          title: "背景样式",
          name: "bgStyle",
          type: 1,
          list: [
            {
              val: "直角",
              icon: "iconPic_square"
            },
            {
              val: "圆角",
              icon: "iconPic_fillet"
            }
          ]
        },
        bgColor: {
          title: "背景颜色",
          name: "bgColor",
          default: [
            {
              item: "#d3e1f6"
            }
          ],
          color: [
            {
              item: "#d3e1f6"
            }
          ]
        },
        textPosition: {
          title: "文本位置",
          type: 0,
          list: [
            {
              val: "居左",
              style: "left",
              icon: "icondoc_left"
            },
            {
              val: "居中",
              style: "center",
              icon: "icondoc_center"
            },
            {
              val: "居右",
              style: "right",
              icon: "icondoc_right"
            }
          ]
        },
        textStyle: {
          title: "标题样式",
          type: 0,
          list: [
            {
              val: "正常",
              style: "normal",
              icon: "icondoc_general"
            },
            {
              val: "斜体",
              style: "italic",
              icon: "icondoc_skew"
            },
            {
              val: "加粗",
              style: "bold",
              icon: "icondoc_bold"
            }
          ]
        },
        fontSize: {
          title: "标题大小",
          val: 14,
          min: 14
        },
        tipSize: {
          title: "文本大小",
          val: 12,
          min: 12
        },
        themeColor: {
          title: "标题颜色",
          name: "themeColor",
          default: [
            {
              item: "#333333"
            }
          ],
          color: [
            {
              item: "#282828"
            }
          ]
        },
        tipColor: {
          title: "文本颜色",
          name: "tipColor",
          default: [
            {
              item: "#333333"
            }
          ],
          color: [
            {
              item: "#333333"
            }
          ]
        },
        prConfig: {
          title: "背景边距",
          val: 10,
          min: 10
        },
        // 页面间距
        mbConfig: {
          title: "页面间距",
          val: 10,
          min: 10
        }
      },
      txtColor: "",
      titleTxt: "",
      tipTxt: "",
      txtPosition: "",
      txtStyle: "",
      themeColor: "",
      tipColor: "",
      txtStyle: "",
      fontSize: 0,
      tipSize: 0,
      mTop: 0,
      pageData: {},
      prConfig: 0,
      bgColor: "",
      bgStyle: 1,
      isOne: 0
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.pageData = this.$store.state.mobildConfig.defaultArray[this.num];
      this.setConfig(this.pageData);
    });
  },
  methods: {
    setConfig(data) {
      if (!data) return;
      if (data.mbConfig) {
        this.titleTxt = data.titleConfig.value;
        this.tipTxt = data.tipTxt.value;
        this.txtColor = data.tipColor.color[0].item;
        this.mTop = data.mbConfig.val;
        this.prConfig = data.prConfig.val;
        this.txtPosition = data.textPosition.list[data.textPosition.type].style;
        this.txtStyle = data.textStyle.list[data.textStyle.type].style;
        this.bgColor = data.bgColor.color[0].item;
        this.fontSize = data.fontSize.val;
        this.themeColor = data.themeColor.color[0].item;
        this.tipSize = data.tipSize.val;
        this.bgStyle = data.bgStyle.type;
      }
    }
  }
};
</script>

<style scoped lang="scss">
.pinkOn {
  border-radius: 14px !important;
}
.m0 {
  margin: 0;
}
.mt10 {
  margin: 10px 0 0;
}
</style>
